<html>
<head><meta charset="utf-8"><title>Move `ItemKind::Impl` into a struct? · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Move.20.60ItemKind.3A.3AImpl.60.20into.20a.20struct.3F.html">Move `ItemKind::Impl` into a struct?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="217563940"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Move%20%60ItemKind%3A%3AImpl%60%20into%20a%20struct%3F/near/217563940" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Move.20.60ItemKind.3A.3AImpl.60.20into.20a.20struct.3F.html#217563940">(Nov 22 2020 at 18:44)</a>:</h4>
<p>I just had to write some code <a href="https://github.com/rust-lang/rust/pull/79312/files?diff=unified&amp;w=1#diff-384affc1b4190940f114f3fcebbf969e7e18657a71ef9001da6b223a036687d9R2010">like this</a>:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="p">(</span><span class="n">trait_</span><span class="p">,</span><span class="w"> </span><span class="n">items</span><span class="p">,</span><span class="w"> </span><span class="n">for_</span><span class="p">,</span><span class="w"> </span><span class="n">unsafety</span><span class="p">,</span><span class="w"> </span><span class="n">generics</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">match</span><span class="w"> </span><span class="o">&amp;</span><span class="n">impl_</span><span class="p">.</span><span class="n">kind</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">hir</span>::<span class="n">ItemKind</span>::<span class="n">Impl</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">of_trait</span><span class="p">,</span><span class="w"> </span><span class="n">items</span><span class="p">,</span><span class="w"> </span><span class="n">self_ty</span><span class="p">,</span><span class="w"> </span><span class="n">unsafety</span><span class="p">,</span><span class="w"> </span><span class="n">generics</span><span class="p">,</span><span class="w"> </span><span class="o">..</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="p">(</span><span class="n">of_trait</span><span class="p">,</span><span class="w"> </span><span class="n">items</span><span class="p">,</span><span class="w"> </span><span class="n">self_ty</span><span class="p">,</span><span class="w"> </span><span class="o">*</span><span class="n">unsafety</span><span class="p">,</span><span class="w"> </span><span class="n">generics</span><span class="p">)</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">        </span><span class="n">_</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">unreachable</span><span class="o">!</span><span class="p">(),</span><span class="w"></span>
<span class="w">    </span><span class="p">};</span><span class="w"></span>
</code></pre></div>
<p>This is really painful to work with and until <a href="https://github.com/rust-lang/rfcs/pull/2593">https://github.com/rust-lang/rfcs/pull/2593</a> lands I don't think there's a way to make it nicer. What do you think about adding a <code>hir::Impl</code> struct that lets you use the fields as named parameters, so you don't have to repeat the names 3 times? The only downside I see is it might be confusing with <code>ImplItem</code>, but we could document that.</p>



<a name="217563960"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Move%20%60ItemKind%3A%3AImpl%60%20into%20a%20struct%3F/near/217563960" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Move.20.60ItemKind.3A.3AImpl.60.20into.20a.20struct.3F.html#217563960">(Nov 22 2020 at 18:45)</a>:</h4>
<p>that would also let me get rid of the <code>unreachable!</code> branch</p>



<a name="217566672"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Move%20%60ItemKind%3A%3AImpl%60%20into%20a%20struct%3F/near/217566672" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Move.20.60ItemKind.3A.3AImpl.60.20into.20a.20struct.3F.html#217566672">(Nov 22 2020 at 19:48)</a>:</h4>
<p>Cc <span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> </p>
<p>Do other ItemKind variants have struct fields?</p>



<a name="217566690"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Move%20%60ItemKind%3A%3AImpl%60%20into%20a%20struct%3F/near/217566690" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Move.20.60ItemKind.3A.3AImpl.60.20into.20a.20struct.3F.html#217566690">(Nov 22 2020 at 19:49)</a>:</h4>
<p>Seems like at least some do</p>



<a name="217566693"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Move%20%60ItemKind%3A%3AImpl%60%20into%20a%20struct%3F/near/217566693" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Move.20.60ItemKind.3A.3AImpl.60.20into.20a.20struct.3F.html#217566693">(Nov 22 2020 at 19:49)</a>:</h4>
<p>I think it should be fine to do so.</p>



<a name="217566696"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Move%20%60ItemKind%3A%3AImpl%60%20into%20a%20struct%3F/near/217566696" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Move.20.60ItemKind.3A.3AImpl.60.20into.20a.20struct.3F.html#217566696">(Nov 22 2020 at 19:49)</a>:</h4>
<p>nice, I'll work on that</p>



<a name="217566700"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Move%20%60ItemKind%3A%3AImpl%60%20into%20a%20struct%3F/near/217566700" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Move.20.60ItemKind.3A.3AImpl.60.20into.20a.20struct.3F.html#217566700">(Nov 22 2020 at 19:49)</a>:</h4>
<p>(once I finish putting out <a href="http://docs.rs">docs.rs</a> fires)</p>



<a name="217566701"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Move%20%60ItemKind%3A%3AImpl%60%20into%20a%20struct%3F/near/217566701" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Move.20.60ItemKind.3A.3AImpl.60.20into.20a.20struct.3F.html#217566701">(Nov 22 2020 at 19:49)</a>:</h4>
<p>Separate PR would be good</p>



<a name="217574345"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Move%20%60ItemKind%3A%3AImpl%60%20into%20a%20struct%3F/near/217574345" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Move.20.60ItemKind.3A.3AImpl.60.20into.20a.20struct.3F.html#217574345">(Nov 22 2020 at 22:46)</a>:</h4>
<p>wow this took way longer than expected</p>



<a name="217574381"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Move%20%60ItemKind%3A%3AImpl%60%20into%20a%20struct%3F/near/217574381" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Move.20.60ItemKind.3A.3AImpl.60.20into.20a.20struct.3F.html#217574381">(Nov 22 2020 at 22:48)</a>:</h4>
<p>lol it <em>already</em> has merge conflicts</p>



<a name="217574596"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Move%20%60ItemKind%3A%3AImpl%60%20into%20a%20struct%3F/near/217574596" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Move.20.60ItemKind.3A.3AImpl.60.20into.20a.20struct.3F.html#217574596">(Nov 22 2020 at 22:53)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pull/79322">https://github.com/rust-lang/rust/pull/79322</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>